package com.alinesno.cloud.initializr.starter.enable;

import java.util.ArrayList;
import java.util.List;

import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.StringUtils;

import com.alinesno.cloud.common.core.auto.constom.CustomAutoConfigurationImportSelector;
import com.alinesno.cloud.initializr.starter.Scan;

/**
 * 自定义扫描范围
 * 
 * @author WeiXiaoJin
 * @since 2020年11月1日 下午4:17:20
 *
 */
public class ConfigurationSelector extends CustomAutoConfigurationImportSelector {

	@Override
	public String[] selectImports(AnnotationMetadata importingClassMetadata) {

		// 此处一定要注意，按最小包扫描原则，避免包到处加载，而导致异常！！！！
		String pkg = Scan.class.getPackage().getName();

		List<String> aop = this.scanComponent(pkg + ".aop");
		List<String> config = this.scanComponent(pkg + ".config");
		List<String> repository = this.scanComponent(pkg + ".repository");
		List<String> service = this.scanComponent(pkg + ".service.impl");
		List<String> strategy = this.scanComponent(pkg + ".strategy");
		List<String> utils = this.scanComponent(pkg + ".utils");

		List<String> list = new ArrayList<String>();
		list.addAll(config);
		list.addAll(aop);
		list.addAll(repository);
		list.addAll(service);
		list.addAll(strategy);
		list.addAll(utils);

		return StringUtils.toStringArray(list);
	}

	@Override
	protected Class<?> getAnnotationClass() {
		return EnableInitializrAdmin.class;
	}
}
